/**
 * 守护线程示例
 */
public class ThreadDemoByDaemon {
    public static void main(String[] args) throws InterruptedException {
        //得到当前的线程(main主线程)
        Thread thread=Thread.currentThread();
        System.out.println("是否是守护线程:"+thread.isDaemon());
        Thread t1=new Thread(()->{
            //得到当前线程
            Thread cThread=Thread.currentThread();
            System.out.println(cThread.getName()+"--是否是守护线程"+cThread.isDaemon());

            Thread tt1=new Thread(()->{
                Thread cThread2=Thread.currentThread();
                System.out.println(cThread2.getName()+"--是否是守护线程"+cThread.isDaemon());

            },"子线程的子线程");
            tt1.start();

        },"子线程1");

        //手动指定线程为守护线程
        t1.setDaemon(true);
        //启动线程
        t1.start();

        //将主线程休眠1s
        Thread.sleep(1000);
    }
}
